﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using MediatR;
using Loong.Domain.Uow;

namespace Loong.Orders
{
    public class CreateOrderHandler : IRequestHandler<CreateOrderComand, string>
    {
        private readonly IUnitOfWorkManager _unitOfWorkManager;

        public CreateOrderHandler(IUnitOfWorkManager unitOfWorkManager)
        {
            _unitOfWorkManager = unitOfWorkManager;
        }

        public async Task<string> Handle(CreateOrderComand request, CancellationToken cancellationToken)
        {
            using (var uow = _unitOfWorkManager.Begin())
            {
                await uow.CompleteAsync();

                return "OrderCreated";
            }
        }
    }
}
